﻿using CWebSocket;
using SocketWebTest.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SocketWebTest.webToNative
{
    public class FormOperaHandler : JsEvent
    {

        /// <summary>
        /// 处理方法，接收参数固定为  Socket 与 string
        /// 对应的URL为 *.openForm
        /// 如果需要向客户端推送消息，则使用 WebSocket.Instance.Send(client, '消息');
        /// </summary>
        /// <param name="client">Socket对象</param>
        /// <param name="message">JSON参数</param>
        public void SetFormPosition(Socket client, string data)
        {
            Console.WriteLine(data);

            Program.form.BeginInvoke((MethodInvoker)delegate ()
            {
                var screenPosition = Newtonsoft.Json.JsonConvert.DeserializeObject<ScreenPosition>(data);

                Program.form.Top = screenPosition.Top;
                Program.form.Left = screenPosition.Left;
            });
        }

        /// <summary>
        /// 处理方法，接收参数固定为  Socket 与 string
        /// 对应的URL为 *.minimize
        /// 如果需要向客户端推送消息，则使用 WebSocket.Instance.Send(client, '消息');
        /// </summary>
        /// <param name="client">Socket对象</param>
        /// <param name="message">JSON参数</param>
        public void minimize(Socket client, string data)
        {
            // 把本窗口最小化
            Program.form.BeginInvoke((MethodInvoker)delegate ()
            {
                Program.form.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            });
        }





    }
}
